package com.xiayuanxing.arithmetic.DataStructures.Search;

/**
 * @program: arithmetic
 * @description: 线性查找法
 * @author: xia yuan xing
 * @create: 2021-09-27 15:50
 */
public class SeqSearch {

    public static void main(String[] args) {
        int[] array = {8,4,5,7,1,3,6,2};
        int index = seqSearch(array, 3);
        System.out.println(index);
    }


    /**
    *@Description: 这里实现的是找到一个符合条件就返回
    *@Param:
    *@return:
    *@Author: xia yuan xing
    *@date: 2021/9/27
    */
    public static  int seqSearch(int[] arr,int value){
        //线性查找就是逐一对比，发现有相同值，就返回下标
        for (int i = 0; i <arr.length ; i++) {
           if (arr[i] == value){
               return i;
           }
        }
        return -1;
    }
}